package com.gitee.faster.webdav.common.structure;

import cn.hutool.core.getter.OptNullBasicTypeFromStringGetter;
import cn.hutool.core.util.ObjectUtil;

import java.util.function.UnaryOperator;

/**
 * @author hongda.li
 */
public class StringValue implements OptNullBasicTypeFromStringGetter<String> {

    private final UnaryOperator<String> mapping;

    public StringValue(UnaryOperator<String> mapping) {
        this.mapping = mapping;
    }

    @Override
    public String getStr(String key, String defaultValue) {
        return ObjectUtil.defaultIfNull(this.mapping.apply(key), defaultValue);
    }
}
